<?php
 
class DamerauLevenshteinMod {

	static function distance($ustr1, $ustr2, $block_size=2, $max_distance=4) {
		if (function_exists('distance_utf')) {
			$a1 = self::utf8_to_unicode_code($ustr1);
			$a2 = self::utf8_to_unicode_code($ustr2);
			return distance_utf($a1, $a2, $block_size, $max_distance);
		} else return levenshtein( $ustr1, $ustr2 );
	}
 
	static function utf8_to_unicode_code($utf8_string){
		$expanded = iconv("UTF-8", "UTF-32", $utf8_string);
		$converted = unpack("L*", $expanded);
		return $converted;
	} 
}